#include "ciEuler.h"

ImprovedEuler::ImprovedEuler(){
	setName("Improved Euler");
	//tx and fx are cleared and set from cInfo when active potential is set.
	//If, for some reason, the active potential is not set and method is initiated we 
	//set tx and fx to 0 and 10 respectivly.
}

ImprovedEuler::ImprovedEuler(double ivy, double ivdy){
	setName("Improved Euler");
	//tx and fx are cleared and set from cInfo when active potential is set.
	//If, for some reason, the active potential is not set and method is initiated we 
	//set tx and fx to 0 and 10 respectivly.
	setStep(0.01);
	set_tx(0);
	set_fx(10);
	set_ty(ivy);
	set_fy(ivy);
	set_tdy(ivdy);
	set_fdy(ivdy);
}


ImprovedEuler::~ImprovedEuler(){
}

void ImprovedEuler::methodStep(double& step, vector<double> &xx, vector<double> &yy, vector<double> &dy, cDY * DY, cPot * V) {
	double k1, k2, l1, l2;
	k1 = dy.back();
	l1 = DY->DE(xx.back(), V->potential(xx.back()),yy.back(),dy.back());
	k2 = dy.back() + step * k1;
	l2 = DY->DE(xx.back() + step, V->potential(xx.back()+step),yy.back()+step*k1, dy.back()+step*l1);
	yy.push_back(yy.back() + step*0.5*(k1+k2));
	dy.push_back(dy.back() + step*0.5*(l1+l2));
	xx.push_back(xx.back()+step);

}
